from typing import Optional, Union, Sequence
from typing_extensions import Self

from nicegui import events
from nicegui.element import Element

class FloatWindow(Element, component='floatwindow.js'):
# class FloatWindow(Element, default_classes='nicegui-column'):

	def __init__(self, title:str, content:str=None) -> None:
		super().__init__()
		self._props['title'] = title
		self._props['content'] = content
		self._props['showcontent'] = False if content is None else True
		self.on('windowhide', self.on_windowhide)

	def updateContent(self, content:str=None) -> None:
		# print(f'updateContent: {content}')
		self._props['content'] = content
		self._props['showcontent'] = False if content is None else True

	def updateTitle(self, title:str) -> None:
		"""
		Updates the title of the Float window
		"""
		# print(f'updateTitle: {title}')
		self._props['title'] = title


	def update(self) -> None:
		"""Force the internal content to be retransmitted to the specified location.
			This method is usually called after the target container is rebuilt.
		"""
		super().update()
		self.run_method('update')

	def show(self) -> None:
		"""
		Shows the Float window
		"""
		self.run_method("showElement")

	def hide(self) -> None:
		"""
		Hides the Float window
		"""
		self.run_method("hideElement")

	def on_windowhide(self, msg) -> None:
		"""
		Called when this float window is hidden.
		"""
		print(f'{msg=}')


	
